package com.springdemo.spring5.service;

import com.springdemo.spring5.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * User: zjz
 * Date: 2022/02/26 11:14
 * Description:
 * Version: V1.0
 */
//在注解里面value属性值，可以省略不写，默认值是类名称首字母小写
@Service(value = "userService")//类似于 <bean id="" class=".." />
public class UserService {
    @Value(value = "zjz")
    private String name;

    //定义dao类型属性
    //不需要添加set方法
    //添加注入属性注解
//    @Autowired//根据类型进行注入
//    @Qualifier(value = "userDaoImpl1")//根据名称注入
//    private UserDao userDao;

    //@Resource 根据类型注入
    @Resource(name = "userDaoImpl1")//根据名称进行注入
    private UserDao userDao;
    public void add(){
        System.out.println("service add..."+name);
        userDao.add();
    }
}
